package com.java.crazy.part6;

import com.java.crazy.base.BaseClass;
import com.java.crazy.part5.类与对象.AnimalBean;
import com.java.crazy.part5.类与对象.ManBean;
import com.java.crazy.part5.类与对象.Person;

public class Test6 extends BaseClass {
    public static void main(String[] args) {
        //6.1 拆箱装箱
//        AutoBoxingUnboxing();
        //6.2 对象
//        MyObject();
        //6.3 类成员
//        MyObjectSon();
        //6.4 final
        MyFinal();
    }

    /**
     * ************************************  final  start **************************************
     */
    //普通代码块
    final int a;

    {
        a = 3;
    }

    //static 静态代码块
    final static int b;

    static {
        b = 4;
    }

    //直接初始化
    final int c = 3;


    final int d;

    //构造器中初始化

    Test6() {
        logi("" + "Test6()");
        d = 2;
    }

    private static void MyFinal() {
        logInfo("\n\n","final  start");
        Test6 test6 = new Test6();
        logi("a=" + test6.a);
        logi("b=" + test6.b);
        logi("c=" + test6.c);
        logi("d=" + test6.d);

        final int e;
        {
            e = 4;
            logi("e=" + e);
        }
        logInfo("","final  end");



    }

    /**
     * ************************************  final  end  **************************************
     */
    private static void MyObjectSon() {
        logi("\n\n************************************  类成员  **************************************");

        Person person2 = null;
        logi("person2.sayObj()等于Person.sayObj()：\t\t" + person2.sayObj());
        logi("\n");
    }

    /**
     * 6.2
     * 对象
     */
    private static void MyObject() {
        logInfo("\n\n","对象");
        AnimalBean animalBean = new AnimalBean();
        logi(animalBean.hashCode());
        logi(animalBean);
        logi(animalBean.toString());
        logi("\n");

        ManBean manBean = new ManBean();
        logi(manBean.hashCode());
        logi(manBean);
        logi(manBean.toString());
        logi("\n");


        Person person = new Person();
        logi(person.hashCode());
        logi(person);
        logi(person.toString());
    }

    /**
     * 6.1
     * 自动装箱拆箱
     */
    private static void AutoBoxingUnboxing() {
        logi("\n\n************************************  拆箱装箱  **************************************");
        logi("拆箱装箱:");
        int age = 128;
        Integer integer = age;
        Integer integer2 = new Integer(age);
        Integer integer3 = age;
        Object object = true;
        int i = integer2;
        if (object instanceof Boolean) {
            boolean b = (boolean) object;
            logi(" (boolean) object:\t\t" + b);
        }
        logi("integer == age:\t\t" + (integer == age));
        logi("integer2 == age:\t\t" + (integer2 == age));
        logi("-128~127时返回true，之外会返回false：integer == integer3 \t\t " + integer + "--" + integer3 + "--" + (integer == integer3));
        logi("integer == i:   \t\t" + integer + "--" + i + "--" + (integer == i));
        //指向了不同的内存地址
        logi("指向了不同的内存地址：\t\t" + integer + "--" + integer2 + "--" + (integer == integer2));
        logi("\n");


        logi("Integer.compare(" + integer2 + "," + integer3 + "): 0相等，1大于，-1小于： " + Integer.compare(integer2, integer3));
        logi("Integer.compare(" + integer2 + ",200): 0相等，1大于，-1小于： " + Integer.compare(integer2, 200));
        logi("Integer.compare(" + integer2 + ",1): 0相等，1大于，-1小于： " + Integer.compare(integer2, 1));
        logi("\n");
        //4294967169
        logi(Integer.toUnsignedString(127));
        logi(Integer.toUnsignedString(-128));
        ;
        logi(Integer.divideUnsigned(-11, 11));
    }
}
